home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ImageLight2 / ImageLight2.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  11.1 KB  |  490 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.event.MouseMotionListener;
  14. import java.awt.image.MemoryImageSource;
  15. import java.awt.image.PixelGrabber;
  16. import java.net.MalformedURLException;
  17. import java.net.URL;
  18. import java.net.URLEncoder;
  19.  
  20. public class ImageLight2 extends Applet implements Runnable, MouseListener, MouseMotionListener {
  21.    boolean loaded;
  22.    Thread thread;
  23.    Image image;
  24.    Image buffer;
  25.    // $FF: renamed from: b java.awt.Graphics
  26.    Graphics field_0;
  27.    Color backColor;
  28.    Color color;
  29.    // $FF: renamed from: wi int
  30.    int field_1;
  31.    // $FF: renamed from: he int
  32.    int field_2;
  33.    int wiIm;
  34.    int heIm;
  35.    int pause = 20;
  36.    static int[] pix;
  37.    static int[] pixnew;
  38.    int radiusIni;
  39.    int radius;
  40.    // $FF: renamed from: R int
  41.    private int field_3;
  42.    // $FF: renamed from: G int
  43.    private int field_4;
  44.    // $FF: renamed from: B int
  45.    private int field_5;
  46.    // $FF: renamed from: X int
  47.    int field_6;
  48.    // $FF: renamed from: Y int
  49.    int field_7;
  50.    int dimMin;
  51.    private String statusBarText;
  52.    private AudioClip sound;
  53.    private AudioClip clicSound;
  54.    private AudioClip enterSound;
  55.    private boolean loopSound;
  56.    private String link;
  57.    // $FF: renamed from: fm java.awt.FontMetrics
  58.    private FontMetrics field_8;
  59.    private String enterText;
  60.    private boolean isEnterTextEnabled;
  61.    private int wiEnterText;
  62.    private int enterTextHeight;
  63.    private Color enterTextColor;
  64.    private int decx;
  65.    private int decy;
  66.  
  67.    public String getAppletInfo() {
  68.       return "Name: ImageLight2\r\nAuthor: Taiji Software\r\n";
  69.    }
  70.  
  71.    public ImageLight2() {
  72.       this.backColor = Color.black;
  73.       this.radiusIni = 30;
  74.       this.color = new Color(210, 220, 130);
  75.       ((Component)this).addMouseListener(this);
  76.       ((Component)this).addMouseMotionListener(this);
  77.    }
  78.  
  79.    public void register() {
  80.       try {
  81.          URL u = new URL("http://www.taijisoftware.com");
  82.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  83.       } catch (Exception e) {
  84.          System.out.println(e);
  85.          this.stop();
  86.       }
  87.    }
  88.  
  89.    public void init() {
  90.       String codeBase = null;
  91.  
  92.       try {
  93.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  94.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  95.          codeBase = codeBase.toUpperCase();
  96.       } catch (Exception var11) {
  97.       }
  98.  
  99.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  100.          String regCode = ((Applet)this).getParameter("registration_code");
  101.          if (regCode == null) {
  102.             regCode = ((Applet)this).getParameter("reg_domain");
  103.             if (regCode == null) {
  104.                this.register();
  105.             } else {
  106.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  107.                   codeBase = "WWW." + codeBase;
  108.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  109.                   codeBase = codeBase.substring(4);
  110.                }
  111.  
  112.                char[] chars = new char[codeBase.length()];
  113.                codeBase.getChars(0, codeBase.length(), chars, 0);
  114.                String key = new String("haricot");
  115.                char[] chars2 = new char[key.length()];
  116.                key.getChars(0, key.length(), chars2, 0);
  117.  
  118.                for(int i = 0; i < codeBase.length(); ++i) {
  119.                   int j;
  120.                   if (i >= key.length()) {
  121.                      j = i - key.length() * (i / key.length());
  122.                   } else {
  123.                      j = i;
  124.                   }
  125.  
  126.                   chars[i] += chars2[j];
  127.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  128.                }
  129.  
  130.                String res = new String(chars);
  131.                if (!res.equalsIgnoreCase(regCode)) {
  132.                   this.register();
  133.                }
  134.             }
  135.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  136.             this.register();
  137.          }
  138.       }
  139.  
  140.       this.getParameters();
  141.       int rgb = this.color.getRGB();
  142.       this.field_3 = (rgb & 16711680) >> 16;
  143.       this.field_4 = (rgb & '\uff00') >> 8;
  144.       this.field_5 = rgb & 255;
  145.       this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image_name"));
  146.       MediaTracker tracker = new MediaTracker(this);
  147.       tracker.addImage(this.image, 0);
  148.  
  149.       try {
  150.          tracker.waitForAll();
  151.          tracker.isErrorAny();
  152.       } catch (Exception e) {
  153.          System.err.println(e);
  154.       }
  155.  
  156.       if (!this.loaded) {
  157.          this.stop();
  158.       }
  159.  
  160.       this.wiIm = this.image.getWidth(this);
  161.       this.heIm = this.image.getHeight(this);
  162.       this.decx = (this.field_1 - this.wiIm) / 2;
  163.       this.decy = (this.field_2 - this.heIm) / 2;
  164.       pix = new int[this.wiIm * this.heIm];
  165.       pixnew = new int[this.wiIm * this.heIm];
  166.       PixelGrabber pixg = new PixelGrabber(this.image, 0, 0, this.wiIm, this.heIm, pix, 0, this.wiIm);
  167.  
  168.       try {
  169.          pixg.grabPixels();
  170.       } catch (InterruptedException var9) {
  171.       }
  172.  
  173.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  174.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  175.       this.field_0 = this.buffer.getGraphics();
  176.       this.field_0.setColor(this.enterTextColor);
  177.       String fontName = ((Applet)this).getParameter("enter_text_font");
  178.       if (fontName == null) {
  179.          fontName = "TimesRoman";
  180.       }
  181.  
  182.       int style = 1;
  183.       String s = ((Applet)this).getParameter("enter_text_style");
  184.       if (s != null) {
  185.          if (s.equals("bold")) {
  186.             style = 1;
  187.          } else if (s.equals("italic")) {
  188.             style = 2;
  189.          } else if (s.equals("bold_italic")) {
  190.             style = 3;
  191.          } else {
  192.             style = 0;
  193.          }
  194.       }
  195.  
  196.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  197.       this.field_8 = this.field_0.getFontMetrics();
  198.       if (this.enterText != null) {
  199.          this.wiEnterText = this.field_8.stringWidth(this.enterText);
  200.       }
  201.  
  202.       this.field_6 = (int)((float)this.wiIm / 2.0F);
  203.       this.field_7 = (int)((float)this.heIm / 2.0F);
  204.       if (this.wiIm >= this.heIm) {
  205.          this.dimMin = this.heIm;
  206.       } else {
  207.          this.dimMin = this.wiIm;
  208.       }
  209.  
  210.       if (this.sound != null) {
  211.          if (this.loopSound) {
  212.             this.sound.loop();
  213.          } else {
  214.             this.sound.play();
  215.          }
  216.       }
  217.  
  218.       this.radius = 0;
  219.       ((Component)this).repaint();
  220.    }
  221.  
  222.    public void getParameters() {
  223.       this.field_1 = ((Component)this).getSize().width;
  224.       this.field_2 = ((Component)this).getSize().height;
  225.       String s = ((Applet)this).getParameter("pause");
  226.       if (s != null) {
  227.          this.pause = Integer.parseInt(s);
  228.       }
  229.  
  230.       this.backColor = this.getColor("background_color");
  231.       ((Component)this).setBackground(this.backColor);
  232.       if (this.getColor("color") != null) {
  233.          this.color = this.getColor("color");
  234.       }
  235.  
  236.       s = ((Applet)this).getParameter("radius");
  237.       if (s != null) {
  238.          this.radiusIni = Integer.parseInt(s);
  239.       }
  240.  
  241.       s = ((Applet)this).getParameter("sound_name");
  242.       if (s != null) {
  243.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  244.       }
  245.  
  246.       s = ((Applet)this).getParameter("loop_sound");
  247.       if (s != null) {
  248.          if (s.equals("yes")) {
  249.             this.loopSound = true;
  250.          } else {
  251.             this.loopSound = false;
  252.          }
  253.       }
  254.  
  255.       s = ((Applet)this).getParameter("clic_sound_name");
  256.       if (s != null) {
  257.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  258.       }
  259.  
  260.       s = ((Applet)this).getParameter("enter_sound_name");
  261.       if (s != null) {
  262.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  263.       }
  264.  
  265.       this.link = ((Applet)this).getParameter("link");
  266.       this.enterText = ((Applet)this).getParameter("enter_text");
  267.       s = ((Applet)this).getParameter("enter_text_height");
  268.       if (s != null) {
  269.          this.enterTextHeight = Integer.parseInt(s);
  270.       }
  271.  
  272.       this.enterTextColor = this.getColor("enter_text_color");
  273.       if (this.enterTextColor == null) {
  274.          this.enterTextColor = Color.white;
  275.       }
  276.  
  277.    }
  278.  
  279.    public Color getColor(String param) {
  280.       String s = ((Applet)this).getParameter(param);
  281.       if (s != null) {
  282.          if (s.substring(0, 1).equals("#")) {
  283.             s = s.substring(1);
  284.             int i = Integer.parseInt(s, 16);
  285.             return new Color(i);
  286.          } else {
  287.             return null;
  288.          }
  289.       } else {
  290.          return null;
  291.       }
  292.    }
  293.  
  294.    public void start() {
  295.       if (this.thread == null) {
  296.          this.thread = new Thread(this);
  297.          this.thread.start();
  298.       }
  299.  
  300.    }
  301.  
  302.    public void stop() {
  303.       if (this.thread != null) {
  304.          this.thread = null;
  305.       }
  306.  
  307.       if (this.sound != null) {
  308.          this.sound.stop();
  309.       }
  310.  
  311.    }
  312.  
  313.    public void run() {
  314.       Thread.currentThread().setPriority(4);
  315.  
  316.       while(true) {
  317.          ((Component)this).repaint();
  318.  
  319.          try {
  320.             Thread.sleep((long)this.pause);
  321.          } catch (InterruptedException var1) {
  322.          }
  323.  
  324.          this.calculatePixels();
  325.       }
  326.    }
  327.  
  328.    public final void paint(Graphics g) {
  329.       if (!this.loaded) {
  330.          this.field_0.setColor(Color.white);
  331.          this.field_0.drawString("loading... please wait", 1, this.field_2 / 2);
  332.          this.loaded = true;
  333.       } else {
  334.          if (this.image != null) {
  335.             this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  336.             this.field_0.drawImage(this.image, this.decx, this.decy, this);
  337.             if (this.isEnterTextEnabled) {
  338.                this.field_0.drawString(this.enterText, (this.field_1 - this.wiEnterText) / 2, this.field_2 / 2);
  339.             }
  340.  
  341.             this.image = null;
  342.          }
  343.  
  344.          g.drawImage(this.buffer, 0, 0, this);
  345.       }
  346.    }
  347.  
  348.    public final void update(Graphics g) {
  349.       this.paint(g);
  350.    }
  351.  
  352.    private final void calculatePixels() {
  353.       for(int i = 0; i < this.heIm; ++i) {
  354.          for(int j = 0; j < this.wiIm; ++j) {
  355.             int k = this.field_6 - this.decx - j;
  356.             int l = this.field_7 - this.decy - i;
  357.             float r1 = (float)Math.sqrt((double)(k * k + l * l));
  358.             if (r1 < (float)this.radius) {
  359.                float r2 = (float)Math.cos((double)r1 * Math.PI / (double)((float)this.radius) / (double)1.5F);
  360.                r2 *= r2;
  361.                int r = ((pix[i * this.wiIm + j] & 16711680) >> 16) + (int)((float)this.field_3 * r2);
  362.                int v = ((pix[i * this.wiIm + j] & '\uff00') >> 8) + (int)((float)this.field_4 * r2);
  363.                int b = (pix[i * this.wiIm + j] & 255) + (int)((float)this.field_5 * r2);
  364.                if (r > 255) {
  365.                   r = 255;
  366.                }
  367.  
  368.                if (v > 255) {
  369.                   v = 255;
  370.                }
  371.  
  372.                if (b > 255) {
  373.                   b = 255;
  374.                }
  375.  
  376.                pixnew[i * this.wiIm + j] = (new Color(r, v, b)).getRGB();
  377.             } else {
  378.                pixnew[i * this.wiIm + j] = pix[i * this.wiIm + j];
  379.             }
  380.          }
  381.       }
  382.  
  383.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  384.    }
  385.  
  386.    public int red(int i, int j) {
  387.       return (pix[i * this.wiIm + j] & 16711680) >> 16;
  388.    }
  389.  
  390.    public int green(int i, int j) {
  391.       return (pix[i * this.wiIm + j] & '\uff00') >> 8;
  392.    }
  393.  
  394.    public int blue(int i, int j) {
  395.       return pix[i * this.wiIm + j] & 255;
  396.    }
  397.  
  398.    public URL giveURL(String url) {
  399.       try {
  400.          if (url.toUpperCase().startsWith("HTTP")) {
  401.             return new URL(url);
  402.          } else if (url.toUpperCase().startsWith("FTP")) {
  403.             int p = url.indexOf(":");
  404.             int p2 = url.indexOf(":", p + 1);
  405.             if (p2 != -1) {
  406.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  407.             }
  408.  
  409.             p = url.indexOf("%40");
  410.             if (p != -1) {
  411.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  412.             }
  413.  
  414.             return new URL(url);
  415.          } else {
  416.             return new URL(((Applet)this).getCodeBase(), url);
  417.          }
  418.       } catch (MalformedURLException e) {
  419.          System.out.println(e);
  420.          return null;
  421.       }
  422.    }
  423.  
  424.    public void mouseClicked(MouseEvent e) {
  425.    }
  426.  
  427.    public void mouseEntered(MouseEvent e) {
  428.       this.radius = this.radiusIni;
  429.       if (this.enterText != null) {
  430.          this.isEnterTextEnabled = true;
  431.          this.field_0.setColor(this.enterTextColor);
  432.          ((Component)this).repaint();
  433.       }
  434.  
  435.       if (this.statusBarText != null) {
  436.          ((Applet)this).showStatus(this.statusBarText);
  437.       }
  438.  
  439.       if (this.enterSound != null) {
  440.          this.enterSound.play();
  441.       }
  442.  
  443.       if (this.link != null) {
  444.          ((Component)this).setCursor(new Cursor(12));
  445.       }
  446.  
  447.    }
  448.  
  449.    public void mouseExited(MouseEvent e) {
  450.       this.radius = 0;
  451.       if (this.isEnterTextEnabled) {
  452.          this.isEnterTextEnabled = false;
  453.          ((Component)this).repaint();
  454.       }
  455.  
  456.       if (this.link != null) {
  457.          ((Component)this).setCursor(new Cursor(0));
  458.       }
  459.  
  460.    }
  461.  
  462.    public void mousePressed(MouseEvent e) {
  463.       if (this.clicSound != null) {
  464.          this.clicSound.play();
  465.       }
  466.  
  467.       if (this.link != null) {
  468.          String target = ((Applet)this).getParameter("target");
  469.          if (target == null) {
  470.             target = "_blank";
  471.          }
  472.  
  473.          URL u = this.giveURL(this.link);
  474.          ((Applet)this).getAppletContext().showDocument(u, target);
  475.       }
  476.  
  477.    }
  478.  
  479.    public void mouseReleased(MouseEvent e) {
  480.    }
  481.  
  482.    public void mouseDragged(MouseEvent e) {
  483.    }
  484.  
  485.    public void mouseMoved(MouseEvent e) {
  486.       this.field_6 = e.getX();
  487.       this.field_7 = e.getY();
  488.    }
  489. }
  490.